package com.zcx.test.controller;

import com.zcx.test.common.vo.ApiResult;
import com.zcx.test.pojo.Role;
import com.zcx.test.pojo.RoleExample;
import com.zcx.test.pojo.User;
import com.zcx.test.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * @author zhaochangxin
 * @date 2022/3/8 16:17
 * 角色模块
 */
@RestController
@RequestMapping("/role")
@Api(tags = "角色模块")
public class RoleController {
    private static final String ROLE_QUERY_SUCCESS = "查询完毕";
    private static final String ROLE_INSERT_SUCCESS = "插入成功";
    private static final String ROLE_DELETE_SUCCESS = "删除成功";
    @Autowired
    RoleService roleService;

    /**
     * queryRoleList 查询所有role接口
     * @param roleExample
     * @return ApiResult
     */
    @RequestMapping("/roleList")
    public ApiResult queryRoleList(RoleExample roleExample) {
        RoleExample.Criteria criteria = roleExample.createCriteria();
        criteria.andCreatedByIsNotNull();
        List<Role> roleList = roleService.queryRoleList(roleExample);
        return ApiResult.success(ROLE_QUERY_SUCCESS,roleList);
    }
    /**
    　* @author zhaochangxin
    　* @Description:通过id查询角色信息
    　* @Param id:
    　* @return: com.zcx.test.common.vo.ApiResult
    　* @date 2022/3/9 17:56
    　* @throws
    　*/
    @ApiOperation(value = "通过id查询角色信息")
    @RequestMapping("/{id}")
    public ApiResult queryRoleById(@PathVariable("id") String id) {
        Role role=roleService.queryRoleByRoleId(id);
        return ApiResult.success(ROLE_QUERY_SUCCESS,role);
    }


}
